<template>
  <div class="filterContainer">
    <div class="filterContent">
      <div class="selType">
        <p>
          <span>问诊类型</span>
        </p>
        <ul class="flex itemList wrap">
          <li
            v-for="(value, index) in selTypeList"
            :key="index"
            @click="selTypeClick(value, index)"
            :class="{resetBtn: value.active}"
          >
            {{value.text}}
            <i class="checked" v-show="value.active"></i>
          </li>
        </ul>
      </div>
      <mu-divider />
      <div class="doctorLevel">
        <p>
          <span>医生职称</span>
          <!-- <span>主治医师</span> -->
        </p>
        <ul class="flex itemList wrap">
          <li
            v-for="(value, index) in doctorLevelList"
            :key="index"
            @click="doctorLevelClick(value, index)"
            :class="{resetBtn: activeLevel == index}"
          >
            {{value.label}}
            <i class="checked" v-show="activeLevel == index"></i>
          </li>
        </ul>
      </div>
      <mu-divider />
      <div class="bottomHandler flex">
        <div>
          <mu-raised-button label="重置" primary fullWidth class="resetBtn" @click="reset()" />
        </div>
        <div class="flex_full">
          <mu-raised-button label="完成" primary fullWidth @click="selOk()" />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { DOCTOR_LEVEL } from "../../api/const";
const ALL_TYPES = '1,2,3,4,5'

export default {
  data() {
    return {
      selTypeList: [
        { text: "不限", id: ALL_TYPES, active: true },
        { text: "图文咨询", id: 1, active: false },
        { text: "复诊配药", id: 2, active: false },
        { text: "电话咨询", id: 3, active: false },
        { text: "视频咨询", id: 4, active: false },
        { text: "云诊室", id: 5, active: false }
      ],
      doctorLevelList: DOCTOR_LEVEL,
      selTypeData: { text: "不限", id: ALL_TYPES },
      doctorLevelData: "",
      activeLevel: 0
    };
  },
  mounted() {
    let busType = this.$route.query.busType;
    if (busType) {
      this.selTypeList.forEach(v => {
        v.active = busType.indexOf(v.id) > -1;
      });
    }
  },
  methods: {
    selTypeClick(value, index) {
      if (index == 0) {
        this.selTypeList.forEach((v, i) => {
          v.active = i === 0
        });
      } else {
        this.selTypeList[0].active = false
        value.active = !value.active;
      }
      this.selTypeData = value;
    },
    doctorLevelClick(value, index) {
      this.doctorLevelData = value.value;
      this.activeLevel = index;
    },
    reset() {
      // 重置类型
      this.selTypeData = this.selTypeList[0];
      this.selTypeList.forEach((v, i) => v.active = i === 0)

      // 重置级别
      this.doctorLevelData = "";
      this.activeLevel = 0;
    },
    selOk() {
      // 单独处理问诊类型的多选
      if (this.selTypeData.id != ALL_TYPES){
        let temp = []
        this.selTypeList.forEach(v => {
          if (v.active){
            temp.push(v.id)
          }
        })
        this.selTypeData.id = temp.join(',')
      }

      this.$emit("selOk", {
        selTypeData: this.selTypeData,
        doctorLevelData: this.doctorLevelData
      });
    }
  }
};
</script>

<style scoped lang="less">
@import "../../common/css/vars";
.filterContainer {
  position: absolute;
  width: 100%;
  top: 44px;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.6);
  border-top: 1px solid @color-border;
  z-index: 99;
}
.filterContent {
  background-color: white;
  color: black;
  > div {
    padding: 10px;
  }
}
.itemList {
  > li {
    color: #4a4a4a;
    width: 30%;
    background-color: white;
    border: 1px solid #e4e4e4;
    border-radius: 3px;
    text-align: center;
    height: 36px;
    line-height: 36px;
    margin: 5px;
    box-sizing: border-box;
    position: relative;
  }
}
.bottomHandler {
  div {
    padding: 5px;
    box-sizing: border-box;
    border: 1px solid transparent;
  }
  div:nth-child(1) {
    width: 32%;
  }
}
.resetBtn {
  color: @color-primary!important;
  background-color: #d3f2e6 !important;
}
.checked {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 18px;
  height: 18px;
  background: url("../../assets/images/ic_pitchon.png");
  background-size: 100%;
}
</style>
